//
//  LoginViewController.swift
//  App_Login
//
//  Created by Flutter on 2021/7/7.
//

import UIKit
import UICore
import SnapKit
import Leaf
import PopMenu
import AudioKit
import SoundpipeAudioKit


class LoginViewController: ViewController {
 

    lazy var loginButton = {
        UIButton(type: .system)
            .leaf
            .backgroundColor(.blue)
            .targetAction(self, #selector(presentMenu))
            .instance
    }()
    
//    lazy var eView: EView = {
//        EView(frame: .zero)
//    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .systemBackground

        
        
//        let pixel = genrateESize(vision: 1.0, distance: 0.5, ppi: 326.0)
//        eView.leaf.add(to: view).snp.makeConstraints {
//            $0.center.equalToSuperview()
//            $0.width.height.equalTo(pixel)
//        }
//        print(eView.direction)
        
        loginButton.frame = CGRect(x: 100.0, y: 100.0, width: 100, height: 100)
        loginButton.leaf.add(to: view).snp.makeConstraints {
            $0.centerX.equalToSuperview()
            $0.width.height.equalTo(100)
            $0.top.equalTo(view.snp.bottom).offset(100)
        }
        
    }
    
//    func genrateESize(vision: CGFloat,distance: CGFloat,ppi:CGFloat) -> CGFloat {
//        let visionDegree = 1/((vision*60.0)*(180/CGFloat.pi))
//        let size = tan(visionDegree)*distance*1000.0
//        let pixel = (size*ppi)/(2*25.4)
//        return pixel*5
//    }
//
    
    
   
    
    // 展示一个弹出菜单
    @objc
    func presentMenu() {
        
//        let currentDirection = eView.rotateRadomly()
//        print(currentDirection)
        
        let osc = Oscillator(amplitude: 10)
        osc.frequency = 500
        let leftPanner = Panner(osc, pan: 1)
        let engine = AudioEngine()
        engine.output = Mixer(leftPanner)
        try! engine.start()
        while true {
            osc.play()
//            sleep(1)
//            osc.stop()
//            sleep(1)
        }
        
        
//        let menuViewController = PopMenuViewController(sourceView: loginButton,actions: [
//            PopMenuDefaultAction(title: "标题1", didSelect: { aciton in
//
//            }),
//            PopMenuDefaultAction(title: "标题2", didSelect: { aciton in
//
//            }),
//        ])
//        present(menuViewController, animated: true, completion: nil)
    }


}
